package com.gzhryc.socket.mosquitto.log;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.gzhryc.common.logging.Logger;
import com.gzhryc.socket.SocketCallback;
import com.gzhryc.socket.SocketNode;

public class SocketErrorLogHandler extends MosquittoLogHandler{
	
	static Logger log = Logger.getLogger(SocketErrorLogHandler.class);
	
	Pattern part = Pattern.compile("Socket error on client (.*), disconnecting");

	public SocketErrorLogHandler(MosquittoLogHandler nextHandler,SocketNode node,SocketCallback callback) {
		super(nextHandler,node,callback);
	}

	@Override
	public boolean execute(String logStr) {
		Matcher mat = part.matcher(logStr);
		if(mat.find()){
			String clientId = mat.group(1);
			log.debug("ClientId:"+clientId+", Socket Error!!!");
			return true;
		}
		return super.execute(logStr);
	}
}
